﻿@model IEnumerable<WebVideo.EntityUser>
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-1.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-ui-1.8.16.custom.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    function deletehis(Username) {
        var c = confirm('Continue delete?');
        if (c) $('#hs' + Username).fadeOut(function () {
            var getURL = '@Url.Action("Delete", "User")';

            $.get(getURL, { "Username": Username }, function (data) {
                if (data == "error") //error
                {
                    $('#nofError').show();
                    $('#nofSuccess').hide();
                    $('#msgNofError').text("Cannot Delete Record");
                }
                else {
                    jQuery(this).remove();
                    $('#nofError').hide();
                    $('#nofSuccess').show();
                    $('#msgNofSuccess').text("Delete Record Ok");
                }
            });
        });
        return false;
    }
</script>
<script type="text/javascript">
    function DeleteRecord(id) {
        var getURL = '@Url.Action("Delete", "User")';
        $.get(getURL, { "id": id }, function (data) {
            if (data == "error") //error
            {
                $('#nofError').show();
                $('#nofSuccess').hide();
                $('#msgNofError').text("Cannot Delete Record");
            }
            else {
                //alert("ok");
                $('#nofError').hide();
                $('#nofSuccess').show();
                $('#msgNofSuccess').text("Delete Record Ok");
            }
        });
    }
    //thây đổi điểm của user
    function ChangePoint(type, username) {
        var getURL = '@Url.Action("ChangePoint", "User")';
        var idd = username + type;
        var value = $("#" + idd).val();
            $.get(getURL, { "type": type, "username": username, "value": value }, function (data) {
                if (data == "error") //error
                {
                    $('#nofError').show();
                    $('#nofSuccess').hide();
                    $('#msgNofError').text("Không thể đổi điểm, xin vui lòng check lại dữ liệu");
                }
                else {
                    $('#nofError').hide();
                    $('#nofSuccess').show();
                    $('#msgNofSuccess').text("Thay đổi thành công");
                }
            });
      
        return false;
      }
</script>
<ul class="maintabmenu multipletabmenu">
    <li class="current"><a href="@Url.Action("Index", "User")" >Index</a></li>
     <li class="current"><a href="#" onclick="return saveExcel();" >Xuất Thông tin User</a></li>
</ul>
<!--maintabmenu-->
<div class="notification msgsuccess" style="display: none" id="nofSuccess">
    <a class="close"></a>
    <p id="msgNofSuccess">This is a success message.</p>
</div>
<!-- notification msgsuccess -->
<div class="notification msgerror" style="display: none" id="nofError">
    <a class="close"></a>
    <p id="msgNofError">This is an error message.</p>
</div>
<!-- notification msgerror -->
<div class="contenttitle">
    <h2 class="form"><span>List User</span></h2>
</div>
<!--contenttitle-->
<table cellpadding="0" cellspacing="0" border="0" class="stdtable" id="dyntable">
    <colgroup>
        <col class="con0" />
        <col class="con1" />
        <col class="con0" />
        <col class="con1" />
        <col class="con0" />
        <col class="con1" />
        <col class="con0" />
        <col class="con1" />
        <col class="con0" />
        <col class="con1" />
    </colgroup>
    <thead>
        <tr>
             <th class="head0">Username</th>
            <th class="head1">Họ Tên</th>
            <th class="head1">Tài Khoản Ngân Hàng</th>
            <th class="head1">Địa Chỉ IP</th>
            <th class="head0">Số Điểm đã Xem Video</th>
            <th class="head1">Số Điểm Bạn Bè cấp 1</th>
            <th class="head1">Số Điểm Bạn Bè cấp 2</th>
            <th class="head0">Trạng Thái</th>
            <th class="head1">Ngày Tạo</th>
            <th class="head1">Hành Động</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th class="head0">Username</th>
            <th class="head1">Họ Tên</th>
            <th class="head1">Tài Khoản Ngân Hàng</th>
            <th class="head1">Địa Chỉ IP</th>
            <th class="head0">Số Điểm Xem Video</th>
            <th class="head1">Số Điểm Bạn Bè cấp 1</th>
            <th class="head1">Số Điểm Bạn Bè cấp 2</th>
            <th class="head0">Trạng Thái</th>
            <th class="head1">Ngày Tạo</th>
            <th class="head1">Hành Động</th>
        </tr>
    </tfoot>
    <tbody>
        @{
            foreach (var item in Model)
            {
                string idd = "hs" + item.UserName.ToString();
            <tr class="gradeX" id="@idd">
                <td>                 
                    @Html.DisplayFor(modelitem => item.UserName)
                </td>
                <td>
                    @Html.DisplayFor(modelitem => item.Name)
                </td>
                <td>
                    @Html.DisplayFor(modelitem => item.BankAccount)
                </td>
                <td>
                    @Html.DisplayFor(modelitem => item.Ip)
                </td>
                <td>
                    @{
                        string id1 = item.UserName.ToString() + "1";
                        string id2 = item.UserName.ToString() + "2";
                        string id3 = item.UserName.ToString() + "3";
                    }
                   <input type ="text" value ="@item.PointVideo" id ="@id1" style="width:50px;" /><button onclick="return ChangePoint('1','@item.UserName');">Ok</button>
                </td>
                <td>
                  <input type ="text" value ="@item.PointFriend1"  id ="@id2" style="width:50px;" /><button onclick="return ChangePoint('2','@item.UserName');">Ok</button>
                </td>
                  <td>
                    <input type ="text" value ="@item.PointFriend2" id ="@id3" style="width:50px;" /><button onclick="return ChangePoint('3','@item.UserName');">Ok</button>
                </td>
                <td>
                     @{
                if (@Html.DisplayFor(modelitem => item.Status).ToString() == "1")
                {
                        <span class="field">Đang hoạt động</span>
                }
                else
                {
                        <span class="field" style="color: red;">Đã bị BAN</span>
                }   
                    }
                </td>
                <td>
                    @Html.DisplayFor(modelitem => item.Date)
                </td>
                 <td class ="eddelete">
                        
                        @Html.ActionLink(" ", "Edit", new { US = @item.UserName }, new { @class = "edit",title="View"  })
                         
                        @{
                if (@Html.DisplayFor(modelitem => item.Status).ToString() == "1")
                {
                            @Html.ActionLink(" ", "Ban", new { US = @item.UserName, l = 2}, new { @class = "ban", title="Ban"  })
                }
                else
                {
                            @Html.ActionLink(" ", "Ban", new { US = @item.UserName, l = 1 }, new { @class = "unban",title="Unban"  })
                }   
                        }
                     <a href="#" class="delete" title="Delete" , onclick='deletehis("@item.UserName")' ></a>
                    </td>
            </tr> 
            }                       
        }
    </tbody>
</table>
<script type="text/javascript"  src="@Url.Content("~/Content/cssAdmin/js/custom/tables.js")" ></script>
<script type="text/javascript"  src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery.dataTables.min.js")" ></script>
<script>

    $(document).ready(function () {
        var table = jQuery("#dyntable").dataTable({
            "bDestroy": true,
            "bProcessing": true,
            "sPaginationType": "full_numbers",
            "aaSorting": [[0, "desc"]],
            "iDisplayLength": 100
        });
    });

    function saveExcel() {
        var postUrl = '@Url.Action("saveExcel", "User")';
        $.post(postUrl, function (data) {
            var strTemp = '@Url.Content("~/Content/!!!")';
            strTemp = strTemp.replace("!!!", data);

            window.location = strTemp;

        });
        return false;
        }

</script>